Skip to content

Reduce MTP command-line validation allocations - #10543

Merged
Amaury Levé (Evangelink) merged 2 commits into
mainfrom
dev/amauryleve/optimize-mtp-host-startup
Aug 11, 2026
Merged

Amaury Levé (Evangelink) merged 2 commits into
mainfrom
dev/amauryleve/optimize-mtp-host-startup

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Summary

  • defer duplicate-provider HashSet allocation until an option name is actually repeated
  • preserve case-insensitive duplicate detection, provider ordering, and existing diagnostics
  • strengthen coverage to verify diagnostics retain all providers across multiple collisions

Performance

A controlled in-process benchmark ran command-line validation 1,000 times with 100 unique options:

Metric Before After Change
Allocated bytes per validation 50,872 B 36,072 B -14,800 B (-29.1%)

Repeated zero-match process startup remained neutral within Windows launch noise: mean 928.23 ms to 927.27 ms and median 888.02 ms to 875.36 ms over 30 warm runs.

Validation

  • built Microsoft.Testing.Platform.UnitTests.csproj for all target frameworks (netstandard2.0, net8.0, net9.0, net462)
  • passed all 2,198 Microsoft.Testing.Platform.UnitTests on net8.0
  • completed three review rounds, including MTP-specific, independent correctness, and adversarial behavioral-equivalence passes

Defer per-option provider HashSet allocation until a duplicate registration is actually encountered.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Keep the deferred HashSet path identical to the previous implementation when one provider repeats an option name.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings August 10, 2026 13:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Reduces allocations during MTP command-line option validation while preserving duplicate-provider diagnostics.

Changes:

  • Lazily allocates provider sets only for duplicated options.
  • Extends coverage to verify three colliding providers retain registration order.
Show a summary per file
File Description
CommandLineOptionsValidator.RegistrationValidation.cs Optimizes duplicate-provider tracking.
CommandLineHandlerTests.cs Verifies all colliding providers are reported.

Review details

Tip

Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

🧵 Parallel-safety audit — PR #10543

Nothing audited here touches process-global state, shared filesystem paths, or [ResourceLock] / [DoNotParallelize] declarations. Nothing to flag for parallel-safety.

The PR only refactors CommandLineOptionsValidator.ValidateOptionsAreNotDuplicated (in-memory dictionary/HashSet allocation optimization, no I/O, no env vars, no statics, no culture/console mutation) and extends CommandLineHandlerTests.ParseAndValidateAsync_DuplicateOptionWithDistinctProviderNames_ReportsAllProviders with a third in-memory mock provider. All state (parse results, provider lists, results) is local to the test method; nothing is shared across tests or processes.

Audited Microsoft.Testing.Platform.UnitTests at scope MethodLevel (from [assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)] in Program.cs), workers CPU count.

Re-run with /parallel-audit.

🤖 Automated content by GitHub Copilot. Generated by the Parallel-safety audit on PR (on open / sync) workflow. · auto · 47.8 AIC · ⌖ 4.37 AIC · ⊞ 24.8K · [◷]( · ◷)

@github-actions

Copy link
Copy Markdown
Contributor

🧪 Expert test review — PR #10543

GradeTestMutationNotesHow to improve
A (90–100) mod CommandLineHandlerTests.
ParseAndValidateAsync_
DuplicateOptionWithDistinctProviderNames_
ReportsAllProviders
3/3 killed Extending from 2 to 3 duplicate providers exercises the new HashSet-promotion branch in the refactored dedup logic and asserts the exact formatted error message. —

This advisory comment was generated automatically. Grades are heuristic and informational — they do not block merging. Re-run with /review-tests.

🤖 Automated content by GitHub Copilot. Generated by the Test Reviewer on PR (on open / sync) workflow. · auto · 40.6 AIC · ⌖ 7.01 AIC · ⊞ 16.9K · [◷]( · ◷)

@Evangelink Amaury Levé (Evangelink) added the state/needs-review Awaiting review from the team. label Aug 11, 2026
@Evangelink
Amaury Levé (Evangelink) merged commit e168ce0 into main Aug 11, 2026
41 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the dev/amauryleve/optimize-mtp-host-startup branch August 11, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state/needs-review Awaiting review from the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants